home *** CD-ROM | disk | FTP | other *** search
Wrap
(*^ ::[paletteColors = 128; showRuler; currentKernel; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e8, 24, "Times"; ; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e6, 18, "Times"; ; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, L1, e6, 14, "Times"; ; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, L1, a20, 18, "Times"; ; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, L1, a15, 14, "Times"; ; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, L1, a12, 12, "Times"; ; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 10, "Times"; ; fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L1, 12, "Courier"; ; fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; ; fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1, 12, "Courier"; ; fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1, 12, "Courier"; ; fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1, 12, "Courier"; ; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, L1, 12, "Courier"; ; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, L1, 10, "Times"; ; fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = Left Header, nohscroll, cellOutline, 12; fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, L1, 12; fontset = Left Footer, cellOutline, blackBox, 12; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 10, "Times"; ; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12, "Courier"; ; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1, 12;] :[font = title; inactive; preserveAspect; startGroup; ] CantorSet.ma :[font = subsubtitle; inactive; preserveAspect; ] Steven R. Dunbar Department of Mathematics and Statistics University of Nebraska-Lincoln :[font = subsubtitle; inactive; preserveAspect; ] David Fowler Department of Curriculum and Instruction University of Nebraska-Lincoln :[font = smalltext; inactive; preserveAspect; right; ] ยช Copyright Steven R. Dunbar, David Fowler, 1992, All rights reserved. T ;[s] 2:0,0;1,1;74,-1; 2:1,0,0,Symbol,0,10,0,0,0;1,9,7,Times,0,10,0,0,0; :[font = section; inactive; preserveAspect; startGroup; ] Implementation :[font = subsection; inactive; preserveAspect; startGroup; ] set up the package context :[font = input; initialization; preserveAspect; startGroup; ] *) BeginPackage["CantorSet`"] (* :[font = output; output; inactive; preserveAspect; endGroup; endGroup; ] "CantorSet`" ;[o] CantorSet` :[font = subsection; inactive; autoActive; preserveAspect; startGroup; ] usage messages for the exported functions and the context itself :[font = input; initialization; preserveAspect; ] *) CantorSet::usage = "CantorSet is a collection of basic routines for building and displaying approximations to the Cantor set and its generalizations" (* :[font = input; initialization; preserveAspect; ] *) intervals::usage = "intervals[n] returns the list of subintervals of {0,1} created by n iterations of the middle third removal process." (* :[font = input; initialization; wordwrap; preserveAspect; ] *) complementaryIntervals::usage = "complementaryIntervals[n] returns the list of subintervals removed in n iterations of the middle third removal process." (* :[font = input; initialization; preserveAspect; ] *) cantorSet::usage = "cantorSet[{a,b},r1,r2,n] returns a list of intervals created by the retaining a portion r1 on the left of the interval {a,b}, a portion r2 on the right, and removing the middle (1-r1-r2) portion." (* :[font = input; initialization; preserveAspect; ] *) complementaryCantorSet::usage = "complementaryCantorSet[{a,b}, r1,r2,n] returns a list of of intervals removed by stage n in the process of creating cantorSet[{a,b},r1,r2,n]." (* :[font = input; initialization; preserveAspect; ] *) showIntervals::usage = "showIntervals[n] gives a graphical representation of the first n stages in the construction of the traditional Cantor set." (* :[font = input; initialization; preserveAspect; ] *) showCantorSet::usage = "showCantorSet[{{a,b}}, r1, r2 ,n] gives a graphical representation of the first n stages in the construction of the generalized Cantor set." (* :[font = input; initialization; preserveAspect; ] *) mapUnion::usage = "mapUnion[intervals_List, affinemaps_List] returns the list which is the union of the images of each of the affine maps from the argument affinemap applied to each of the intervals in the argument intervals." (* :[font = input; initialization; wordwrap; preserveAspect; ] *) showMapUnion::usage = "showMapUnion[intervals_List, affinemaps_List, n] gives a graphical representation of the first n stages of the iterated function system given by affinemaps applied to the intervals." (* :[font = input; initialization; wordwrap; preserveAspect; ] *) psi::usage = "psi[{a,b}, r1, r2, n] returns a Line graphics object which the stage n piecewise-linear approximation to the Cantor function on the genaralized Cantor set on interval {a,b} with preservation ratios r1,r2." (* :[font = input; initialization; wordwrap; preserveAspect; endGroup; ] *) cantorFunction::usage = "cantorFunction[n] returns a Line graphics object which the stage n piecewise-linear approximation to the classical Cantor function." (* :[font = subsection; inactive; preserveAspect; startGroup; ] set the private context :[font = input; initialization; preserveAspect; startGroup; ] *) Begin["`Private`"] (* :[font = output; output; inactive; preserveAspect; endGroup; endGroup; ] "CantorSet`Private`" ;[o] CantorSet`Private` :[font = subsection; inactive; preserveAspect; startGroup; ] definition of auxiliary functions :[font = text; inactive; preserveAspect; ] These definitions are adapted from S. Wagon, Mathematica in Action, Section 4.2, W. H. Freeman, 1991 ;[s] 5:0,0;46,1;57,2;58,3;68,4;102,-1; 5:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0; :[font = input; initialization; autoActive; preserveAspect; startGroup; ] *) removePortions[{a_,b_}, r1_, r2_] := {{a,a+r1*(b-a)}, {b-r2*(b-a),b}} /; ((r1+r2<1) && NumberQ[N[a]] && NumberQ[N[b]]) (* :[font = input; initialization; preserveAspect; endGroup; ] *) removePortions[intervals_List, r1_, r2_] := Flatten[Map[removePortions[# ,r1,r2] &, intervals],1]/; Length[intervals[[1]]] > 1 (* :[font = input; initialization; preserveAspect; endGroup; ] *) lines[n_Integer, l_List] := Map[Line[{{#[[1]], n+.5}, {#[[2]], n+.5}}] &,l]; (* :[font = input; initialization; preserveAspect; ] *) showStages[stage_List] := Module[ {level}, level = Length[stage]-1; Show[ Graphics[ Map[lines[level--,#] &, stage ] ], Axes->Automatic, AxesOrigin->{0,0}, Ticks->{Automatic, None} ] ] (* :[font = input; initialization; preserveAspect; ] *) psinodes[interval_, r1_, r2_, n_] := Module[ {ci = complementaryCantorSet[interval, r1,r2,n]}, nodepts = Flatten[{interval[[1]],ci,interval[[2]]}]; heights = Flatten[{0, Table[{j*2^(-n), j*2^(-n)}, {j, Length[ci]} ], 1 } ]; Transpose[ {nodepts, heights}] ] (* :[font = subsection; inactive; preserveAspect; startGroup; ] definition of the exported functions :[font = input; initialization; preserveAspect; startGroup; ] *) cantorSet[interval_, r1_, r2_, n_] := cantorSet[interval, r1, r2, n] = removePortions[cantorSet[interval,r1,r2,n-1], r1, r2] (* :[font = input; initialization; preserveAspect; ] *) cantorSet[interval_,r1_,r2_,1] = removePortions[interval,r1,r2]; (* :[font = input; initialization; preserveAspect; ] *) complementaryCantorSet[interval_, r1_, r2_, n_] := Partition[ Drop[Rest[Flatten[ cantorSet[interval, r1,r2,n]]],-1],2] (* :[font = input; initialization; preserveAspect; ] *) intervals[n_] := cantorSet[{0,1}, 1/3,1/3,n] (* :[font = input; initialization; preserveAspect; endGroup; ] *) complementaryIntervals[n_] := Partition[ Drop[Rest[Flatten[intervals[n]]], -1],2] (* :[font = input; initialization; preserveAspect; ] *) showCantorSet[intervals_List, r1_, r2_, n_] := showStages[ NestList[ removePortions[#, r1,r2] &, intervals, n]] (* :[font = input; initialization; preserveAspect; endGroup; ] *) showIntervals[n_] := showCantorSet[{{0,1}}, 1/3, 1/3,n] (* :[font = input; initialization; preserveAspect; ] *) mapUnion[interval_List, affinemap_List] := Apply[ Union, Table[ Map[ affinemap[[i,1]] + #*affinemap[[i,2]] &, interval, {2}], {i,Length[affinemap]}]] (* :[font = input; initialization; preserveAspect; ] *) showMapUnion[interval_List, affinemap_List, n_] := showStages[ NestList[ mapUnion[#, affinemap] &, interval, n ] ] (* :[font = input; initialization; preserveAspect; ] *) psi[interval_, r1_, r2_, n_] := Line[psinodes[interval, r1, r2, n]] (* :[font = input; initialization; preserveAspect; ] *) cantorFunction[n_] := psi[{0,1}, 1/3,1/3, n] (* :[font = subsection; inactive; preserveAspect; startGroup; ] epilog :[font = input; initialization; preserveAspect; ] *) End[] (* end the private context *) (* :[font = input; initialization; wordwrap; preserveAspect; ] *) Protect[intervals, complementaryIntervals, showCantorSet, showIntervals, mapUnion, showMapUnion, psi, cantorFunction] (* :[font = input; initialization; preserveAspect; endGroup; endGroup; endGroup; ] *) EndPackage[] (* end the package context *) (* ^*)